<template>
  <el-card style="max-width: 99%">
    <template #header>
      <div class="card-header">
        <span>订单管理</span>
      </div>
    </template>
    <el-row style="margin-bottom: 20px">
      <el-col :span="6">
        <el-form :model="form" style="max-width: 250px;margin-left: 25px">
          <el-form-item label="订单编号">
            <el-select v-model="classification" placeholder="请选择" style="width: 100%">
                <el-option label="全部" value="0"></el-option>
                <el-option label="飞机票" value="1"></el-option>
                <el-option label="景点票" value="2"></el-option>
                <el-option label="汽车票" value="3"></el-option>
                <el-option label="船票" value="4"></el-option>
                <el-option label="酒店" value="5"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="18">
        <el-button type="primary" @click="cx()">搜索</el-button>
        <el-button @click="cz()">重置</el-button>
      </el-col>
    </el-row>
    <el-table :data="list" border style="margin-bottom: 15px">
      <el-table-column prop="startTime" label="开始时间" width="180" />
      <el-table-column prop="endTime" label="结束时间" width="180" />
      <el-table-column prop="orderNumber" label="订单编号" width="180" />
      <el-table-column prop="orderName" label="订单名称" />
      <el-table-column prop="classification" label="订单分类">
        <template #default="scope">
          <span v-if="scope.row.classification == '1'">飞机票</span>
          <span v-if="scope.row.classification == '2'">景点票</span>
          <span v-if="scope.row.classification == '3'">汽车票</span>
          <span v-if="scope.row.classification == '4'">船票</span>
          <span v-if="scope.row.classification == '5'">酒店</span>
        </template>
      </el-table-column>
      <el-table-column prop="price" label="订单价格" />
      <el-table-column prop="status" label="订单状态">
        <template #default="scope">
          <el-tag type="danger" v-if="scope.row.status == '1'">待支付</el-tag>
          <el-tag type="primary" v-if="scope.row.status == '2'">已支付</el-tag>
          <el-tag type="success" v-if="scope.row.status == '3'">已完成</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" >
        <template #default="scope">
          <el-button :icon="View" circle @click="openTc(scope.row.id)"/>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin: 0 auto;width: 300px">
      <el-pagination @current-change="handleCurrentChange"
                     size="small" background layout="prev, pager, next" :total="count" :page-size=pageSize class="mt-4"/>
    </div>
  </el-card>

  <el-dialog v-model="dialogFormVisible" :before-close="qx" title="订单详情" width="500">
    <el-form :model="orderForm" style="margin-right: 60px;margin-left: 60px">
      <el-form-item label="用户编号" prop="uid">
        <el-input v-model="orderForm.uid" autocomplete="off" />
      </el-form-item>
      <el-form-item label="订单编号" prop="orderNumber">
        <el-input v-model="orderForm.orderNumber" autocomplete="off" />
      </el-form-item>
      <el-form-item label="订单名称" prop="orderName">
        <el-input v-model="orderForm.orderName" autocomplete="off" />
      </el-form-item>
      <el-form-item label="订单分类" prop="classification">
        <el-input v-model="orderForm.classification" autocomplete="off" />
      </el-form-item>
      <el-form-item label="订单金额" prop="price">
        <el-input v-model="orderForm.price" autocomplete="off" />
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime">
        <el-input v-model="orderForm.startTime" autocomplete="off" />
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-input v-model="orderForm.endTime" autocomplete="off" />
      </el-form-item>
      <el-form-item label="订单状态" prop="status">
        <el-input v-model="orderForm.status" autocomplete="off" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="qx">取消</el-button>
        <el-button type="primary" @click="qd()">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import {selectOrderList, selectOrderById } from "@/api/vue3";
import {View} from "@element-plus/icons-vue";
export default {
  name: 'Order',
  computed: {
    View() {
      return View
    }
  },
  data(){
    return{
      classification:0, //订单编号
      list:[],//订单列表
      pageNum:1,//当前页码
      pageSize:5,//每页显示条数
      count:0,//总条数
      dialogFormVisible:false,//对话框显示
      orderForm:{},
    }
  },
  mounted() {
    this.selList()
  },
  methods:{
    selList(){
      selectOrderList(this.classification,this.pageNum,this.pageSize).then(res=>{
        console.log(res)
        this.list=res.data.data.list
        this.count=res.data.data.count
      })
    },
    handleCurrentChange(val) {//当前页码改变的事件
      this.pageNum = val;
      this.selList()
    },
    //打开弹窗
    openTc(id){
      this.dialogFormVisible= true
      selectOrderById(id).then(res=>{
        console.log(res)
        this.orderForm=res.data.data.data
      })
    },
    cx(){
      this.orderForm
      this.selList()
    },
    cz(){
      this.classification=0
      this.selList()
    },
    qx(){
      this.dialogFormVisible= false
    },
    qd(){
      this.dialogFormVisible= false
    }
  }
}
</script>

<style scoped>
.el-card{
  width: 100%;
  height: 600px;
  background-color: white;
  margin-top: 20px;
  border-radius: 30px;
}
.el-table{
  margin: 0 auto;
  width: 96%;
}
</style>